﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<script src='<%= Url.Content("~/Content/PrayTimes.js")%>' type="text/javascript"></script>
<div class="widget">
    <div class="title"><span>مواقيت الصلاة</span></div>
    <div id="info">
        <%--<div id="next-pray" style="clear:both">remains</div>--%>
        <table id="pray-details" cellpadding="5px">
            
        </table>
    </div>
</div>

<script id="prayerTimeTemplate" type="text/x-jquery-tmpl">
    <tr>
        <th>
            ${PrayCaption}
         </th>
        <td>${PrayTime}</td>
   </tr>
</script>
<script type="text/javascript">
    //This will sort your array
    function getRemaningtime(times) {
        
        var x = new Date();
        var h = x.getHours();
        var m = x.getMinutes();
        for (var i in times) {
            var t = times[i];
            var ts = t.split(":");
            var f_h = parseInt(ts[0]);
            var f_m = parseInt(ts[1]);
            
            
        }
        
        
    }
    $(document).ready(function () {
        var _times = [];
        $("#pray-details").html("");
        // if the browser supports the w3c geo api
        if (navigator.geolocation) {
            // get the current position
            navigator.geolocation.getCurrentPosition(
                          function (position) {
                              var lat = position.coords.latitude;
                              var lon = position.coords.longitude;
                              var times = prayTimes.getTimes(new Date(), [lat, lon], +2);
                              _times = times;
                              var d = [];
                              for (var i in times) {
                                  if (i == "fajr" || i == "dhuhr" || i == "asr" || i == "maghrib" || i == "isha") {
                                      d.push({ PrayCaption: i, PrayTime: times[i] });
                                  }
                              }
                              $("#prayerTimeTemplate").tmpl(d).appendTo("#pray-details");
                              getRemaningtime(_times);
                          },
                          function (error) {
                              alert('ouch');
                          });
                      } //if
       


    });
</script>
